package com.ternnetwork.batch.reader;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.persistence.EntityManagerFactory;

import org.springframework.batch.item.ItemReader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.ternnetwork.batch.item.database.DecreaseResultListByUpdateJpaPagingItemReader;
import com.ternnetwork.batch.model.TestUser;





/**
 * 
 * @author xuwenfeng
 *
 */
@Configuration
public class TestUserJpaPagingItemReaderConfiguration {
	@Resource
    private EntityManagerFactory entityManager; 
	
	
	
	@Bean("testUserJpaPagingItemReader")
	public ItemReader<TestUser> getItemReader(){
		
		DecreaseResultListByUpdateJpaPagingItemReader<TestUser> itemReader=new DecreaseResultListByUpdateJpaPagingItemReader<TestUser>();
		itemReader.setEntityManagerFactory(entityManager);
		itemReader.setPageSize(3);
		
		
		itemReader.setQueryString("from TestUser where id=:id");
		Map<String,Object> parameterValues=new HashMap<String,Object>(5);
		parameterValues.put("id", "1");
		itemReader.setParameterValues(parameterValues);
		
	    //所有ItemReader和ItemWriter实现都会在ExecutionContext提交之前将其当前状态存储在其中,如果不希望这样做,可以设置setSaveState(false)
		itemReader.setSaveState(true);
		
		return itemReader;
		
	}
	

}
